<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2024/12/16
  Time: 15:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>

        #logo{
            margin-left:150px;
        }


        .login-container {
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
            background: #fff;
            border-radius: 4px;
        }

        .login-tabs {
            display: flex;
            border-bottom: 1px solid #eee;
            margin-bottom: 24px;
        }

        .tab-item {
            flex: 1;
            text-align: center;
            padding: 12px;
            cursor: pointer;
            color: #666;
            position: relative;
        }

        .tab-item.active {
            color: #00c250;
        }

        .tab-item.active:after {
            content: '';
            position: absolute;
            bottom: -1px;
            left: 0;
            width: 100%;
            height: 2px;
            background: #00c250;
        }

        .login-form {
            display: none;
        }

        .login-form.active {
            display: block;
        }

        .input-group {
            margin-bottom: 16px;
            position: relative;
        }

        .prefix-select {
            position: absolute;
            left: 0;
            top: 0;
            height: 100%;
            padding: 0 12px;
            display: flex;
            align-items: center;
            border-right: 1px solid #ddd;
        }

        .form-input {
            width: 100%;
            padding: 12px;
            padding-left: 56px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
        }

        .verification-group {
            display: flex;
            gap: 12px;
        }

        .verification-group .form-input {
            flex: 1;
        }

        .verify-code-button {
            white-space: nowrap;
            padding: 0 16px;
            background: #f5f5f5;
            border: 1px solid #ddd;
            border-radius: 4px;
            cursor: pointer;
        }

        .login-button {
            width: 100%;
            padding: 12px;
            background: #00c250;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            margin: 24px 0;
        }

        .login-button:hover {
            background: #00b048;
        }

        .bottom-links {
            display: flex;
            justify-content: space-between;
            margin-bottom: 24px;
        }

        .bottom-links a {
            color: #666;
            text-decoration: none;
        }

        .social-login {
            display: flex;
            justify-content: center;
            gap: 24px;
            margin: 24px 0;
        }

        .social-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #f5f5f5;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .social-icon img {
            width: 24px;
            height: 24px;
        }

        .checkbox-container {
            display: flex;
            align-items: center;
            gap: 8px;
            cursor: pointer;
        }

        .checkbox-container input {
            display: none;
        }

        .checkmark {
            width: 16px;
            height: 16px;
            border: 1px solid #ddd;
            border-radius: 2px;
            position: relative;
        }

        .checkbox-container input:checked + .checkmark:after {
            content: '';
            position: absolute;
            left: 5px;
            top: 2px;
            width: 3px;
            height: 8px;
            border: solid #00c250;
            border-width: 0 2px 2px 0;
            transform: rotate(45deg);
        }

        .terms-agreement {
            margin-top: 24px;
            font-size: 12px;
            color: #666;
        }

        .terms-agreement a {
            color: #00c250;
            text-decoration: none;
        }


        #yidongdenglv{
            position: absolute;
            left: 1100px;
            top: 110px;
        }

        #bottom-copy{
            margin-left: 500px;
            color: #999999;
           font-size: 12px;
        }
    </style>
</head>
<body>
<div id="logo">
    <img src="static/img/PS2lfS0492.jpg">
</div>


<div>
    <img src="static/img/1ux2scxdGKc.jpg">
</div>


<div id="yidongdenglv">
    <div class="login-container">
        <div class="login-tabs">
            <div class="tab-item active" data-tab="password">账号密码登录</div>
            <div class="tab-item" data-tab="verify">验证码登录</div>
        </div>

        <!-- Password Login Form -->
        <div class="login-form active" id="password-login">
            <div class="input-group">
                <div class="prefix-select">
                    <span>+86</span>
                    <i class="arrow-down"></i>
                </div>
                <input type="text" placeholder="手机号/邮箱" class="form-input">
            </div>
            <div class="input-group">
                <input type="password" placeholder="输入密码" class="form-input">
            </div>
            <label class="checkbox-container">
                <input type="checkbox" id="autoLogin">
                <span class="checkmark"></span>
                <span class="label-text">30天内自动登录</span>
            </label>
            <button class="login-button">登录</button>
        </div>

        <!-- Verification Code Login Form -->
        <div class="login-form" id="verify-login">
            <div class="input-group">
                <div class="prefix-select">
                    <span>+86</span>
                    <i class="arrow-down"></i>
                </div>
                <input type="text" id="phone-rongyao" placeholder="手机号" class="form-input">
            </div>
            <div class="input-group verification-group">
                <input id="valCode" type="text" placeholder="输入验证码" class="form-input">
                <button class="verify-code-button">获取验证码</button>
            </div>
            <button class="login-button">登录</button>
        </div>






        <!-- Bottom Links -->
        <div class="bottom-links">
            <a href="#" class="register-link">新用户注册</a>
            <a href="#" class="forgot-link">忘记密码</a>
        </div>

        <!-- Social Login -->
        <div class="social-login">
            <a href="#" class="social-icon wechat"><img src="static/img/微信图片_20241216170226.png" alt="微信"></a>
            <a href="#" class="social-icon qq"><img src="static/img/微信图片_20241216170220.png" alt="QQ"></a>
            <a href="#" class="social-icon alipay"><img src="static/img/微信图片_20241216170211.png" alt="支付宝"></a>
            <a href="#" class="social-icon weibo"><img src="static/img/微信图片_20241216170207.png" alt="微博"></a>
        </div>

        <!-- Terms Agreement -->
        <div class="terms-agreement">
            <label class="checkbox-container">
                <input type="checkbox" id="agreeTerms">
                <span class="checkmark"></span>
                <span class="label-text">登录即代表您已阅读并同意<a href="#">《服务协议及隐私政策》</a></span>
            </label>
        </div>
    </div>

</div>
<div id="bottom-copy">Copyright © 2002-2024 版权所有 同程网络科技股份有限公司 苏ICP证B2-20100204</div>

<script type="text/javascript" src="https://code.jquery.com/jquery-3.7.1.js"></script>
<script>
    $(document).ready(function() {
        // Tab switching
        $('.tab-item').click(function() {
            const tab = $(this).data('tab');

            // Update active tab
            $('.tab-item').removeClass('active');
            $(this).addClass('active');

            // Show corresponding form with fade effect
            $('.login-form').removeClass('active').fadeOut(200);
            $("#"+tab+"-login").fadeIn(200).addClass('active');

        });

        // Verification code countdown
        $('.verify-code-button').click(function() {

            let phone = $("#phone-rongyao").val();
            let reg = /^1[3456789][0-9]{9}$/
            if(!reg.test(phone)){
                alert("请填写正确的手机号码");
            }else{
                //发送异步请求
                sendSms(phone);
                //倒计时
                const button = $(this);
                let countdown = 60;

                button.prop('disabled', true);

                const timer = setInterval(function() {
                    countdown--;
                    button.text(countdown,"秒后重试");

                    if (countdown <= 0) {
                        clearInterval(timer);
                        button.prop('disabled', false);
                        button.text('获取验证码');
                    }
                }, 1000);
            }





        });


        $("#valCode").blur(function(){
            let valCode = $(this).val();
            let reg = /^\d{4}$/
            if(!reg.test(valCode)){
                alert("请输入正确的验证码格式，4位纯数字");
            }else{
                valSmsCode(valCode);
            }
        });

    //手机号验证
        function sendSms(phone){
            $.ajax({
                url:"/sendSms",
                type:"post",
                data:{
                    phone:phone
                },
                dataType:"json",
                success(data){
                    if(data.code === "0000"){
                        alert("发送成功");
                    }else {
                        alert("发送失败,你还没有注册");
                    }
                }
            })
        }



        // Form validation
        $('.login-button').click(function(e) {
            e.preventDefault();

            const form = $(this).closest('.login-form');
            const phone = form.find('input[type="text"]').first().val();
            const password = form.find('input[type="password"]').first().val();


            if (!phone) {
                alert('请输入手机号');
                return;
            }

            if (!$('#agreeTerms').is(':checked')) {
                alert('请阅读并同意服务协议及隐私政策');
                return;
            }


            //判断输入的是密码是否为空，从而判断是密码登录还是验证码登录.
            if(password!==undefined){
                let reg = /^1[3456789][0-9]{9}$/
                if (!reg.test(phone)){
                    alert("请输入正确的手机号码格式")
                    return
                }

                //密码登录
                $.ajax({
                    url:"/gyhlogin",
                    type:"post",
                    data:{phone:phone,password:password},
                    dataType:"text",
                    async:false,
                    success:function (data) {
                        if(data==="success"){
                            window.location.href="index.jsp"
                        }else {
                            alert(data)
                        }
                    }
                })
            }else {
                //1手机验证码登录
                //1.1 获取手机号码
               /* let phone = $("#phone-rongyao").val();*/
                //1.2获取验证码
                let valCode = $("#valCode").val();
                //登录验证

                valSmsCode(valCode,phone)

            }






            // Add your login logic here

        });


        function valSmsCode(valCode,phone){

            $.post("/valSmsCode",{phone:phone,valCode:valCode},function(data){
                if(data.code === "0000"){
                    //登录成功，跳转主页面
                    window.location.href="index.jsp"
                }
            },"json");
        }

        // Prevent form submission on enter
        $('input').keypress(function(e) {
            if (e.which === 13) {
                e.preventDefault();
                $(this).closest('.login-form').find('.login-button').click();
            }
        });
    });
</script>
</body>
</html>
